#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
typedef struct{
    char *addr;
    int data;
}Rose_type;

void *red_thread(void *arg)
{
    char code = *(char *)arg;
    printf("红玫瑰开启了她的旅程\n");

    char buff[100];
    while (1)
    {
        fgets(buff, sizeof(buff), stdin); // 读取键盘输入
        if (buff[0] == code)
        {
            printf("红玫瑰结束了她的旅程\n");
            Rose_type *redrose = malloc(sizeof(redrose));
            redrose->addr = "去了上海";
            redrose->data = 16;
            return redrose;
        }
        else
        {
            printf("红玫瑰告诉你她的秘密%s\n", buff);
        }
    }
}

void *white_thread(void *arg)
{
    char code = *(char *)arg;
    printf("白玫瑰开启了她的旅程\n");

    char buff[100];
    while (1)
    {
        fgets(buff, sizeof(buff), stdin); // 读取键盘输入
        if (buff[0] == code)
        {
            printf("白玫瑰结束了她的旅程\n");

            Rose_type *whiterose = malloc(sizeof(whiterose));
            whiterose->addr = "去了北京";
            whiterose->data = 30;
            return whiterose;
        }
        else
        {
            printf("白玫瑰告诉你她的秘密%s\n", buff);
        }
    }
}
int main(int argc, char const *argv[])
{
    pthread_t red_pt, white_pt;
    char red = 'r';
    char white = 'w';
    pthread_create(&red_pt, NULL, red_thread, &red);
    pthread_create(&white_pt, NULL, white_thread, &white);

    Rose_type *red_jj;
    Rose_type *white_jj;
    pthread_join(red_pt, (void **)&red_jj);
    pthread_join(white_pt, (void **)&white_jj);

    printf("红玫瑰的结局她%d号去了%s\n", red_jj->data,red_jj->addr);
    printf("白玫瑰的结局她%d号去了%s\n", white_jj->data,white_jj->addr);
    return 0;
}
